/*
 * @Author: 韩富贵 hanxzi@163.com
 * @Date: 2022-08-17 19:09:12
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-09-14 17:35:25
 */
import React, { useState, useEffect } from 'react';
import ReactECharts from 'echarts-for-react';
import * as echarts from 'echarts';
import cloneDeep from 'lodash/cloneDeep';
import merge from 'lodash/merge';
import 'echarts-wordcloud';
const defaultOption = {};
const WordCloud: React.FC<any> = (props) => {
  const [chartOption, setChartOption] = useState({});
  const resolveData = () => {
    let series = [];
    let option: any = {};
    if (props.series && props.series instanceof Array) {
      series = props.series.map((item: any) => merge({}, item));
    }
    option.series = series;
    setChartOption(option);
  };

  const getOption = () => {
    return cloneDeep(chartOption);
  };

  useEffect(() => {
    resolveData();
  }, [props.loading]);
  return (
    <ReactECharts
      echarts={echarts}
      {...props}
      option={getOption()}
      notMerge={true}
    />
  );
};

export default WordCloud;
